# Maintainer: Gaetan Bisson <bisson@archlinux.org>
# Contributor: Tobias Kieslich <tobias@justdreams.de>
# Contributor: tobias <tobias@archlinux.org>

pkgname=inkscape
pkgver=1.2.2
_tag='b0a8486541ac36327488da641d58a86bee2f07ad' # git rev-parse INKSCAPE_${pkgver/./_}
pkgrel=7
pkgdesc='Professional vector graphics editor'
url='https://inkscape.org/'
license=('GPL' 'LGPL')
arch=('x86_64')
makedepends=('cmake' 'boost' 'git')

depends=(
	'boost-libs'
	'dbus-glib'
	'double-conversion'
	'gc'
	'graphicsmagick'
	'gsl'
	'gspell'
	'gtkmm3'
	'lcms2'
	'lib2geom'
	'libcdr'
	'libjpeg-turbo'
	'libsoup'
	'libvisio'
	'libxslt'
	'poppler-glib'
	'potrace'
	'python'
	'python-cssselect'
	'python-lxml'
	'python-numpy'
	'ttf-font'
)

optdepends=(
	'fig2dev: xfig input'
	'gvfs: import clip art'
	'pstoedit: latex formulas'
	'scour: optimized SVG output, some extensions'
	'texlive-core: latex formulas'
)

#source=("https://media.inkscape.org/dl/resources/file/${pkgname}-${pkgver}.tar.bz2")
source=("git+https://gitlab.com/inkscape/inkscape.git#tag=${_tag}"
        'inkscape-extensions::git+https://gitlab.com/inkscape/extensions.git'
        'inkscape-lib2geom::git+https://gitlab.com/inkscape/lib2geom.git'
        'inkscape-themes::git+https://gitlab.com/inkscape/themes.git'
        'inkscape-extras-extensions-gcodetools::git+https://gitlab.com/inkscape/extras/extensions-gcodetools.git'
        'inkscape-extras-extension-manager::git+https://gitlab.com/inkscape/extras/extension-manager.git'
        'inkscape-extras-inkscape-import-clipart::git+https://gitlab.com/inkscape/extras/inkscape-import-clipart.git'
        'inkscape-extras-extension-xaml::git+https://gitlab.com/inkscape/extras/extension-xaml.git')
sha256sums=('SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP')

_backports=(
)

prepare() {
	cd "${pkgname}"
	git submodule set-url share/extensions ../inkscape-extensions/
	git submodule set-url src/3rdparty/2geom ../inkscape-lib2geom/
	git submodule set-url share/themes ../inkscape-themes/
	git -c protocol.file.allow=always submodule update --init

	( cd share/extensions/
	  git submodule set-url other/gcodetools ../inkscape-extras-extensions-gcodetools/
	  git submodule set-url other/inkman ../inkscape-extras-extension-manager/
	  git submodule set-url other/clipart ../inkscape-extras-inkscape-import-clipart/
	  git submodule set-url other/extension-xaml ../inkscape-extras-extension-xaml/
	  git -c protocol.file.allow=always submodule update --init )

	local _c
	for _c in "${_backports[@]}"; do
		git log --oneline -1 "${_c}"
		git cherry-pick -n "${_c}"
	done
}

build() {
	mkdir -p build
	export PKG_CONFIG_PATH='/usr/lib/imagemagick6/pkgconfig'
	cmake -H${pkgname} -Bbuild \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX:PATH=/usr \
		-DWITH_DBUS=ON \

	cmake --build build
}

package() {
	DESTDIR="${pkgdir}" cmake --build build --target install
}
